var orderService = require('../service/order.service');


module.exports={
    findOrdersByStatus:findOrdersByStatus,
    updateOrders:updateOrders
}

function findOrdersByStatus(req,res,next) {
    var mId = req.session.merchant._id;
    var status = req.params.status;
    console.log(status);
    var response={};
    orderService.findOrdersByStatus(mId,status,function (err,doc) {
        if(err){
            console.log("error"+Error(err));
            response.result=false;
            response.code = constant.ServerDown;
            res.json(response);
        }else{
            if(doc){
                response.result=true;
                response.obj=doc;
                res.json(response);
            }else{
                response.result=false;
                response.code=constant.NoOrders;
                res.json(response);
            }
        }
    });
}

function updateOrders(req,res,next){
    var body = req.body;
    var oId = body._id;
    var status = body.status;
    var response={};
    orderService.updateOrders(oId,status,function (err,doc) {
        if(err){
            console.log("error"+Error(err));
            response.result=false;
            response.code = constant.ServerDown;
            res.json(response);
        }else{

            response.result=true;
            res.json(response);

        }
    });
}